<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    x:Class="OpenLS.Chart.UI.LegendResources"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:charts="http://schemas.Kherty.com/office/2007/chart"
  xmlns:chartui="clr-namespace:OpenLS.Chart.UI"                   
    xmlns:drawing2="clr-namespace:OpenLS.Drawing.UI;assembly=OpenLS.Drawing.UI"                   
    xmlns:Internals="clr-namespace:OpenLS.Chart.UI.Internals"                   
    xmlns:Internals1="clr-namespace:OpenLS.Drawing.UI.Internals;assembly=OpenLS.Drawing.UI"                    
    >
  <DataTemplate DataType="{x:Type charts:Legend}">
        <Grid>
            <Rectangle Style="{x:Static chartui:ShapedObjectResources.ShapedObjectStyle}"/>
                <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource Self}, 
                    Path=(chartui:ChartElement.ChartArea).PlotArea.Charts[0].Series}" 
                          Margin="4" Background="Transparent" Focusable="True" MouseDown="ItemsControl_MouseDown" Name="itemsControl"
                  chartui:ChartElement.Legend="{Binding}">
                    <ItemsControl.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="{x:Static ApplicationCommands.Delete}"/>
                        <Separator/>
                        <MenuItem Command="{x:Static chartui:ChartCommands.Format3DRotation}"/>
                        <Separator/>
                        <MenuItem Command="{x:Static chartui:ChartCommands.FormatLegend}"/>
                    </ContextMenu>
                </ItemsControl.ContextMenu>
                <ItemsControl.CommandBindings>
                    <CommandBinding Command="{x:Static ApplicationCommands.Delete}" Executed="OnDeleteLegend"/>
                    <CommandBinding Command="{x:Static chartui:ChartCommands.Format3DRotation}" Executed="OnFormat3DRotation"/>
                    <CommandBinding Command="{x:Static chartui:ChartCommands.FormatLegend}" Executed="OnFormatLegend"/>
                </ItemsControl.CommandBindings>
                <ItemsControl.ItemTemplate>
                    <HierarchicalDataTemplate>
                        <StackPanel Orientation="Horizontal" Name="panel">
                            <Rectangle Margin="2" Width="7" Height="7" Name="legendrect" Stroke="Black">
                                <Rectangle.Fill>
                                    <MultiBinding>
                                        <MultiBinding.Converter>
                                            <Internals1:FillPropertiesToBrushConverter/>
                                        </MultiBinding.Converter>
                                        <Binding Path="ShapeProperties.FillProperties"/>
                                        <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                    </MultiBinding>
                                </Rectangle.Fill>
                            </Rectangle>
                            <ContentControl Content="{Binding Text.ActualValue}"/>
                        </StackPanel>
                        <HierarchicalDataTemplate.Triggers>
                            <DataTrigger Binding="{Binding ShapeProperties.FillProperties}" Value ="{x:Null}">
                                <Setter TargetName ="legendrect"  Property ="Fill">
                                    <Setter.Value>
                                        <MultiBinding Converter="{x:Static Internals:ChartConverters.PatternConverter}">
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(chartui:ChartElement.Style)"/>
                                            <Binding Path="Index"/>
                                            <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                                        </MultiBinding>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </HierarchicalDataTemplate.Triggers>
                    </HierarchicalDataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Position}" Value="{x:Static charts:LegendPosition.Bottom}" >
                <Setter TargetName="itemsControl" Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"></StackPanel>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
            <DataTrigger Binding="{Binding Position}" Value="{x:Static charts:LegendPosition.Top}" >
                <Setter TargetName="itemsControl" Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"></StackPanel>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
            <DataTrigger Value="True" >
            	<DataTrigger.Binding>
            		<Binding RelativeSource="{RelativeSource Self}" Path="(chartui:ChartElement.ChartArea).PlotArea.Charts[0].Series[0]" 
                             Converter="{x:Static Internals1:DrawingConverters.IsOfTypeConverter}" ConverterParameter="{x:Type charts:PieSeries}"/>
            	</DataTrigger.Binding>
                <Setter TargetName="itemsControl" Property="Tag" Value="{Binding RelativeSource={RelativeSource Self}, Path=(chartui:ChartElement.ChartArea).PlotArea.Charts[0].Series[0], Converter={x:Static Internals:ChartConverters.ViewModelFactory}}"></Setter>
                <Setter TargetName="itemsControl" Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Values}" />
               <!-- <Setter TargetName="itemsControl" Property="ItemTemplate">
                	<Setter.Value>
                        <DataTemplate>
                            <TextBlock Text="Hello"></TextBlock>
                        </DataTemplate>
                    </Setter.Value>
                </Setter> -->
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

</ResourceDictionary>